package pl.th.permission.plugin;

import com.android.build.api.instrumentation.AsmClassVisitorFactory;
import com.android.build.api.instrumentation.ClassContext;
import com.android.build.api.instrumentation.ClassData;
import com.android.build.api.instrumentation.InstrumentationParameters;

import org.gradle.internal.impldep.org.jetbrains.annotations.NotNull;
import org.objectweb.asm.ClassVisitor;

import pl.th.permission.plugin.node.PermissionClassNode;

@SuppressWarnings("NullableProblems")
public abstract class CustomClassVisitorFactory implements
        AsmClassVisitorFactory<InstrumentationParameters.None> {

    @Override
    @NotNull
    public ClassVisitor createClassVisitor(@NotNull ClassContext classContext,
                                           @NotNull ClassVisitor classVisitor) {
        final String clzName = classContext.getCurrentClassData().getClassName();
        System.out.println("========================");
        System.out.println("createClassVisitor: " + clzName);
        System.out.println("========================");
        return new PermissionClassNode(classVisitor);
    }

    @Override
    public boolean isInstrumentable(@NotNull ClassData classData) {
        return true;
    }
}
